package comet;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class DepartementTestBean implements DepartementTestBeanRemote {

	@PersistenceContext(name = "Departement")
	private EntityManager em; //L'Entity Manager

	public void addDepartement(Departement var) {
		em.persist(var);
	}

	public Departement rechercherDepartement(String var) {
		return em.find(Departement.class, var);
	}

	public void deleteDepartement(String var) {
		Departement resReq = rechercherDepartement(var);
		if (resReq != null) {
			em.remove(resReq);
		}
	}

	public List<Departement> listerTousLesDepartement() {
		return em.createQuery("SELECT * FROM TableDepartement  ")
				.getResultList();
	}

	public Departement updateDepartement(Departement var1, Departement var2) {
		Departement var = em.find(Departement.class, var1.getNom());
		if (var != null) {
			var.setNom(var2.getNom());

		}

		return var;
	}

}
